//
//  ZCRankingListModelMoreData.m
//
//  Created by   on 16/2/26
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ZCRankingListModelMoreData.h"


NSString *const kZCRankingListModelMoreDataVoteCount = @"vote_count";
NSString *const kZCRankingListModelMoreDataJoinCount = @"join_count";
NSString *const kZCRankingListModelMoreDataViewCount = @"view_count";
NSString *const kZCRankingListModelMoreDataVoteid = @"vote_id";

@interface ZCRankingListModelMoreData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ZCRankingListModelMoreData

@synthesize voteCount = _voteCount;
@synthesize joinCount = _joinCount;
@synthesize viewCount = _viewCount;
@synthesize voteid = _voteid;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.voteCount = [[self objectOrNilForKey:kZCRankingListModelMoreDataVoteCount fromDictionary:dict] doubleValue];
            self.joinCount = [[self objectOrNilForKey:kZCRankingListModelMoreDataJoinCount fromDictionary:dict] doubleValue];
            self.viewCount = [[self objectOrNilForKey:kZCRankingListModelMoreDataViewCount fromDictionary:dict] doubleValue];
        self.voteid = [[self objectOrNilForKey:kZCRankingListModelMoreDataVoteid fromDictionary:dict] doubleValue];
    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.voteCount] forKey:kZCRankingListModelMoreDataVoteCount];
    [mutableDict setValue:[NSNumber numberWithDouble:self.joinCount] forKey:kZCRankingListModelMoreDataJoinCount];
    [mutableDict setValue:[NSNumber numberWithDouble:self.viewCount] forKey:kZCRankingListModelMoreDataViewCount];
    [mutableDict setValue:[NSNumber numberWithDouble:self.voteid] forKey:kZCRankingListModelMoreDataVoteid];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.voteCount = [aDecoder decodeDoubleForKey:kZCRankingListModelMoreDataVoteCount];
    self.joinCount = [aDecoder decodeDoubleForKey:kZCRankingListModelMoreDataJoinCount];
    self.viewCount = [aDecoder decodeDoubleForKey:kZCRankingListModelMoreDataViewCount];
    self.voteid = [aDecoder decodeDoubleForKey:kZCRankingListModelMoreDataVoteid];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_voteCount forKey:kZCRankingListModelMoreDataVoteCount];
    [aCoder encodeDouble:_joinCount forKey:kZCRankingListModelMoreDataJoinCount];
    [aCoder encodeDouble:_viewCount forKey:kZCRankingListModelMoreDataViewCount];
     [aCoder encodeDouble:_voteid forKey:kZCRankingListModelMoreDataVoteid];
}

- (id)copyWithZone:(NSZone *)zone
{
    ZCRankingListModelMoreData *copy = [[ZCRankingListModelMoreData alloc] init];
    
    if (copy) {

        copy.voteCount = self.voteCount;
        copy.joinCount = self.joinCount;
        copy.viewCount = self.viewCount;
        copy.voteid = self.voteid;
    }
    
    return copy;
}


@end
